/***************************************************************
 *  Copyright (c) 2007 by GroupMe! Team (www.groupme.net)
 *  All rights reserved
 *
 *  This file is part of the GroupMe! Project. You can utilize
 *  software of the GroupMe! project under the terms of the 
 *  GNU Lesser General Public License as published by the
 *  Free Software Foundation in version 2.1.
 * 
 *  The GNU Lesser General Public License can be found at:
 *  http://www.gnu.org/licenses/lgpl.html
 *
 *  This copyright notice MUST APPEAR in all copies of the file!
 ***************************************************************/
package net.groupme.model;

import java.net.URI;
import java.net.URL;
import java.util.Collection;

import net.groupme.exceptions.DeleteFailedException;
import net.groupme.exceptions.IDNotFoundException;
import net.groupme.exceptions.InsertFailedException;
import net.groupme.exceptions.UpdateFailedException;
import net.groupme.model.dao.ResourceDAO;
import net.groupme.model.rdf.Statement;

/**
 * This class implements the Resource object {@link net.groupme.model.Resource}
 * for the GroupMe! project. created on 16.04.2007
 * 
 * @author Mischa Frank <a
 *         href="mailto:code@planetfrank.net">code@planetfrank.net</a>
 * 
 * @version 0.1
 * 
 */

public class ResourceImpl implements Resource {

	private ResourceDAO resourceDAO = null;

	public ResourceImpl() {
	}

	public ResourceImpl(ResourceDAO resourceDAO) {
		this.resourceDAO = resourceDAO;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#addTag(net.groupme.model.User,
	 *      net.groupme.model.Tag)
	 */
	public void addTag(User tagger, Tag tag) throws InsertFailedException {
		this.resourceDAO.addTag(tagger, tag);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#addTag(net.groupme.model.User,
	 *      net.groupme.model.Tag, net.groupme.model.Group)
	 */
	public void addTag(User tagger, Tag tag, Group group)
			throws InsertFailedException {
		this.resourceDAO.addTag(tagger, tag, group);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#addTag(net.groupme.model.User,
	 *      net.groupme.model.Tag, net.groupme.model.Group, java.lang.Double)
	 */
	public void addTag(User tagger, Tag tag, Group group, Double importance)
			throws InsertFailedException {
		this.resourceDAO.addTag(tagger, tag, group, importance);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#getDescription()
	 */
	public String getDescription() {
		return this.resourceDAO.getDescription();
	}
	
	/**
	 * Returns the Id of the Resource.
	 * @return the Id of the Resource
	 */
	public String getId(){
		return this.resourceDAO.getId();
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Identifiable#getLabel()
	 */
	public String getLabel() {
		return this.resourceDAO.getLabel();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#getName()
	 */
	public String getName() {
		return this.resourceDAO.getName();
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#getDateCreated()
	 */
	public String getDateCreated(){
		return this.resourceDAO.getDateCreated();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#getTags()
	 */
	public Collection<Tag> getTags() {
		return this.resourceDAO.getTags();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#getTags(net.groupme.model.Group)
	 */
	public Collection<Tag> getTags(Group group) {
		return this.resourceDAO.getTags(group);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#getTags(net.groupme.model.User)
	 */
	public Collection<Tag> getTags(User tagger) {
		return this.resourceDAO.getTags(tagger);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#getTags(net.groupme.model.User,
	 *      net.groupme.model.Group)
	 */
	public Collection<Tag> getTags(User tagger, Group group) {
		return this.resourceDAO.getTags(tagger, group);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#getType()
	 */
	public String getType() {
		return this.resourceDAO.getType();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Identifiable#getURI()
	 */
	public URI getURI(){
		return this.resourceDAO.getURI();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#getURL()
	 */
	public URL getURL() {
		return this.resourceDAO.getURL();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#removeTag(net.groupme.model.User,
	 *      net.groupme.model.Tag, net.groupme.model.Group)
	 */
	public void removeTag(User tagger, Tag tag, Group group)
			throws DeleteFailedException {
		this.resourceDAO.removeTag(tagger, tag, group);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Identifiable#setDescription(java.lang.String)
	 */
	public void setDescription(String description) throws UpdateFailedException {
		this.resourceDAO.setDescription(description);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Identifiable#setLabel(java.lang.String)
	 */
	public void setLabel(String label) {
		this.resourceDAO.setLabel(label);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#setName(java.lang.String)
	 */
	public void setName(String name) throws UpdateFailedException {
		this.resourceDAO.setName(name);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#setType(java.lang.String)
	 */
	public void setType(String type) throws UpdateFailedException {
		this.resourceDAO.setType(type);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.groupme.model.Resource#setURL(java.net.URL)
	 */
	public void setURL(URL url) throws UpdateFailedException {
		this.resourceDAO.setURL(url);
	}

	/* (non-Javadoc)
	 * @see net.groupme.model.Resource#addStatement(net.groupme.model.rdf.Statement)
	 */
	public void addStatement(String property, String object, String datatype) throws IDNotFoundException, InsertFailedException {
		this.resourceDAO.addStatement(property, object, datatype);
	}

	/* (non-Javadoc)
	 * @see net.groupme.model.Resource#getStatements()
	 */
	public Collection<Statement> getStatements() {
		return this.resourceDAO.getStatements();
	}

	/* (non-Javadoc)
	 * @see net.groupme.model.Resource#removeStatement(net.groupme.model.rdf.Statement)
	 */
	public void removeStatement(Statement statement) throws DeleteFailedException {
		this.resourceDAO.removeStatement(statement);
	}

	/* (non-Javadoc)
	 * @see net.groupme.model.Resource#getGroups()
	 */
	public Collection<Group> getGroups() {
		return this.resourceDAO.getGroups();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Resource){
			return this.resourceDAO.getId().equals(((Resource)obj).getId());
		}
		return super.equals(obj);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return this.resourceDAO.getId().hashCode();
	}
}
